{include file="header/index" /}
<div class="newContentBox">
    <form action="{:url('index')}" class="layui-form reset-form">
        <div class="newForm">
            <div class="newGroup">
                <div class="newLabel inputText">标题</div>
                <div class="newGroupInput">
                    <input type="text" id="key" name="key" value="{$val}" placeholder="输入需查询的标题" class="layui-input cover_layui_i" />
                </div>
            </div>
            <div class="newGroup newBtnBox">
                <button type="submit" class="newBtnDefault newBtnPrimary">搜索</button>
                <button type="button" id="reset" class="newBtnDefault">重置</button>
            </div>
        </div>
    </form>
    <!-- 分割部分 -->
    <div class="newDivision"></div>
    <div class="newListPart">
        <div class="newTitleBox">
<!--            <span class="layui-inline newListTitle">配置列表</span>-->
            <div class="layui-inline newTitleBtnBox">
                <a href="{:url('add_config')}"><button type="button"  class="newBtnDefault newBtnPrimary">添加配置</button></a>
            </div>
        </div>
        <div class="newTableBox">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>名称</th>
                        <th>标题</th>
                        <th>类型</th>
                        <th>分组</th>
                        <th>创建时间</th>
                        <th>更新时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr> 
                </thead>          
                <tbody id="list-content">
                    {foreach name="list" item="vo"}
                    <tr class="long-td">
                        <td>{$vo.id}</td>
                        <td>{$vo.name}</td>
                        <td>{$vo.title}</td>
                        <td>{$vo.type|get_config_type}</td>
                        <td>{$vo.group|get_config_group}</td>
                        <td>{$vo.create_time}</td>
                        <td>{$vo.update_time}</td>
                        <td>
                            {if condition="$vo['status'] == 1"}
                                <a class="red" href="javascript:;" onclick="status_config({$vo.id});">
                                    <div id="zt{$vo.id}"><span class="label label-info">开启</span></div>
                                </a>
                            {else/}
                                <a class="red" href="javascript:;" onclick="status_config({$vo.id});">
                                    <div id="zt{$vo.id}"><span class="label label-danger">禁用</span></div>
                                </a>
                            {/if}
                        </td>
                        <td>
                            <a href="{:url('Config/edit_config',['id'=>$vo.id])}" class="btn btn-success btn-xs newBtnDefault"> 编辑</a>&nbsp;&nbsp;
                            <a href="javascript:;" onclick="del_config({$vo.id},this)" class="btn btn-success btn-xs newBtnDefault newBtnRed"> 删除</a>
                        </td>
                    </tr>
                {/foreach}
                </tbody>
            </table>
            <div class="pageBox">
                <span>
                    <!--批量删除-->
                </span>
                <div class="newPage" id="page"></div>
            </div>
            

        </div>

    </div>
</div>
<script type="text/javascript">

  var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl;
  console.log("{$nowpage}");

  var count = "{$count}";
  var nowpage = "{$nowpage}";
  var pageSize = "{$pageSize}";
  console.log('count',count)
  console.log('nowpage',nowpage)
  console.log('pageSize',pageSize)

  laypage.render({
      elem: 'page' //注意，这里的 test1 是 ID，不用加 # 号
      ,count: count //数据总数，从服务端得到
      ,curr: nowpage
      ,limit: pageSize
      ,prev: '上一页'//上一页
      ,next: '下一页'//下一页
      ,first: '首页'//首页
      ,last: '尾页'//尾页
      ,layout: ['count','prev', 'pageBox', 'next','skip']
      ,jump: function(obj, first) {
          //页数跳转
          //obj包含了当前分页的所有参数，比如：
          console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
          console.log(obj.limit); //得到每页显示的条数
          //首次不执行
          if(!first){
              //do something
              location.href = '?page='+obj.curr;
          }
      }
  });
  // 重置
  $("#reset").click(function() {
      $('#key').val('');
      location.href = '?page='+1;
  });

/**
 * [del_config 删除配置]
 * @Author[田建龙 864491238@qq.com]
 * @param   {[type]}    id [配置id]
 */
function del_config(id,obj){
    parent.layer.confirm('确认删除此配置?', {icon: 3, title:'提示'}, function(index){
        //do something
        $.getJSON('./del_config', {'id' : id}, function(res){
            if(res.code == 1){
                parent.layer.msg(res.msg,{icon:1,time:1500});
                $(obj).parents("tr").remove()
            }else{
                parent.layer.msg(res.msg,{icon:2,time:1500});
            }
        });

        layer.close(index);
    })

}

/**
 * [status_config 配置状态]
 * @param  {[type]} val [description]
 * @Author[田建龙 864491238@qq.com]
 */
function status_config(val){
    $.post('{:url("status_config")}',
    {id:val},
    function(data){

        if(data.code==1){
            var a='<span class="label label-danger">禁用</span>'
            $('#zt'+val).html(a);
            parent.layer.msg(data.msg,{icon:2,time:1500,shade: 0.1,});
            return false;
        }else{
            var b='<span class="label label-info">开启</span>'
            $('#zt'+val).html(b);
            parent.layer.msg(data.msg,{icon:1,time:1500,shade: 0.1,});
            return false;
        }

    });
    return false;
}


</script>
</body>
</html>